// @ts-check
/**
 * @type {chrome.runtime.ManifestBase}
 */
const MANIFEST = {
    manifest_version: 3,
    // 请使用英文名， 将用于css前缀、全局代码内嵌id等
    name: "f2e-crx-creator",
    version_name: '0.1.0',
    homepage_url: "https://gitee.com/f2e-server/f2e-crx-creator",
    description: "创建chrome扩展开发工具，提供一些常用工具，开发环境tsx编译、热更新等功能",
    version: "0.1.0",
    icons: {
        "16": "assets/icons/crx_16.png",
        "48": "assets/icons/crx_48.png",
        "128": "assets/icons/crx_128.png"
    },
    content_scripts: [
        {
            matches: ["<all_urls>"],
            js: ["js/content.js"],
            css: ["assets/base.css"],
            run_at: "document_end"
        }
    ],
    permissions: [
        "cookies",
        "contextMenus",
        "activeTab",
        "background",
        "tabCapture"
    ],
    minimum_chrome_version: "70",
}

/**
 * @type {Partial<chrome.runtime.ManifestV3> & Pick<chrome.runtime.ManifestV3, 'manifest_version'>}
 */
const MANIFEST_V3 = {
    manifest_version: 3,
    background: {
        service_worker: "js/background.js"
    },
    action: {
        default_icon: "assets/icons/crx_16.png",
        default_title: "F2E Popup",
        default_popup: "assets/html/popup.html"
    },
    host_permissions: [
        "<all_urls>"
    ],
    web_accessible_resources: [
        {
            resources: ["assets/**"],
            matches: ["<all_urls>"]
        }
    ],
    minimum_chrome_version: "88",
}

/**
 * @type {Partial<chrome.runtime.ManifestV2> & Pick<chrome.runtime.ManifestV2, 'manifest_version'>}
 */
const MANIFEST_V2 = {
    manifest_version: 2,
    background: {
        scripts: [MANIFEST_V3.background?.service_worker || ''],
        persistent: true,
    },
    browser_action: MANIFEST_V3.action,
    web_accessible_resources: ["assets/**"],
}


/**
 * @param {chrome.runtime.Manifest['manifest_version']} version 
 * @returns {chrome.runtime.Manifest}
 */
const Manifest = (version = 3) => {
    switch (version) {
        case 2:
            return { ...MANIFEST, ...MANIFEST_V2 }
        case 3:
        default:
            return { ...MANIFEST, ...MANIFEST_V3 }
    }
}
module.exports = Manifest